#include "Main.h"

VOID __declspec(naked) GameInput_Interception()
{
	__asm
	{
		PUSHAD
		MOV ECX,DWORD PTR SS:[ECX+0x3FC]
		MOV ECX,DWORD PTR DS:[ECX+0x1E0]
		MOV ECX,DWORD PTR DS:[ECX+0x1E4]
		CALL GameInput
		POPAD
		PUSH -1
		MOV EAX, [GAME_GameInput_I]
		PUSH EAX
		JMP GAME_GameInput_II
	}
}

VOID __declspec(naked) GameGetTLSValue_Interception()
{
	__asm
	{
		CALL GAME_TlsGet_I
		TEST EAX,EAX
		JNZ Exit
		MOV EAX,DWORD PTR DS:[GAME_TlsGet_II]
		MOV EAX,[EAX]
		MOV EAX,DWORD PTR DS:[EAX]
		ADD EAX,0x24
		MOV EAX,DWORD PTR DS:[EAX+8]
		MOV EAX,DWORD PTR DS:[EAX]
		MOV EAX,DWORD PTR DS:[EAX+0x208]
Exit:
		RETN
	}
}

VOID __declspec(naked) GameSetUnitLifeAfterHit_Interception()
{
	__asm
	{
		// Old Code
		MOV DWORD PTR SS:[ESP+0x44],ECX
		PUSHAD
		MOV EDX, ECX
		MOV ECX, EDI
		CALL GameSetUnitLifeAfterHit
		POPAD
		LEA EAX, [ESP+0x44]
		RETN
	}
}

VOID __declspec(naked) GameSetPlayerResource_Interception()
{
	__asm
	{
		MOV EDX, [ESP+0x8]
		PUSH EBX
		MOV EBX, [ESP+0x8]
		PUSHAD
		PUSH EBX
		Call GameSetPlayerResource
		POPAD
		POP EBX
		SUB ESP, 0x0C
		PUSH EBP
		PUSH EDI
		JMP [GAME_SetPlayerResource_I]
	}
}

VOID __declspec(naked) GameCreateUnit_Interception()
{
	__asm
	{
		PUSHAD
		MOV ECX, EAX
		CALL GameCreateUnit
		POPAD
		RETN 0x18
	}
}

VOID __declspec(naked) GameSetUnitClassid_Interception()
{
	__asm {
		MOV EAX, [ESP+0x4]
		PUSHAD
		MOV EDX, EAX
		CALL GameSetUnitClassId
		POPAD
		JMP [GAME_UnitSetClassId_I]
	}
}